package repository

import (
	"context"
	"server_go/internal/model"
)

type UsersRepository interface {
	GetUsersByAccount(ctx context.Context, account string) (*model.Users, error)
}

func NewUsersRepository(
	repository *Repository,
) UsersRepository {
	return &usersRepository{
		Repository: repository,
	}
}

type usersRepository struct {
	*Repository
}

func (r *usersRepository) GetUsersByAccount(ctx context.Context, account string) (*model.Users, error) {
	var users model.Users
	err := r.DB(ctx).Where("account = ? ", account).First(&users).Error
	if err != nil {
		return nil, err
	}
	return &users, nil
}
